<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	<script type="text/javascript">

	　　if (window.ActiveXObject && !window.XMLHttpRequest) {

	　　window.XMLHttpRequest=function() {

	　　return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');

	　　};

	　　}//取得XMLHttpRequest对象

	　　function checkName(path){

	　　//path是取得系统路径
	　　var view_name=document.getElementById("showMsg");
		//alert(path + "/user/addUCheckName");
	　　var req=new XMLHttpRequest();

			　　if (req) {
		
				　　req.onreadystatechange=function() {
			
					　　if (req.readyState==4 && req.status==200) {//判断状态，4是已发送，200已完成
				
					　　if(req.responseText==0){
				
						　　view_name.style.color='green';
					
						　　view_name.innerHTML='该用户名可以正常使用';
				
					　　}else if(req.responseText==1){
				
						　　view_name.style.color='red';
					
						　　view_name.innerHTML='该用户名已经被使用';
				
					　　}else{
				
						　　view_name.style.color='red';
					
						　　view_name.innerHTML='该用户名含有非法字符！';
				
					　　}
				
					　　}
		
			　　}

				var name = document.getElementById("name").value;
				//alert(name);
			　　req.open('POST', path+'/user/addUCheckName',true);//struts
		
			　　//req.open(’POST’, path+’/ajax.servlet’);//servlet
		
			　　//req.open(’POST’, path+’/ajax.action’);//webwork
		
			　　req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
			　　req.send("addName=" + name);//发送参数如果有参数req.send("username="+user_name);用request取得
	
		　　}

	　　}
			
		function checkNull() {
		
			var name = document.getElementById("name").value;
			var password = document.getElementById("password").value;
			//alert(name + " === " + password);
			if(name == "" || password == "") {
					alert("用户名或密码不能为空！");
					return false;
				}
			var form1 = document.getElementById("form1");
			form1.action = "/practiesCheckBox_008/user/addUser"
			//alert("form1.action");
			form1.submit();
			document.getElementById("name").Value="";
			document.getElementById("password").Value="";
			}

	</script>
  </head>
  
  <body>
   <form action="" method="post" id="form1">
	   <table>
	   	<%--<td><input type="hidden" name="loginname" value="<%=request.getParameter("name") %>" /></td>
	   	<td><input type="hidden" name="loginpassword" value="<%=request.getParameter("password") %>" /></td>
	   	--%>
	   	<tr><td>用户名:</td><td><input type="text" name="name" id="name" onblur="checkName('<%=request.getContextPath()%>');"/></td><td><span id="showMsg"></span></td></tr>
	   	<tr><td>密	码:</td><td><input type="text"  name="password" id="password" /></td></tr>
	   	<tr>
	   	<td><input type="button" value="添加" id="delu" onclick="checkNull();"></td>
	   	<td><input type="button" name="button2" id="button2" value="返回" onclick="Javascript:location.href='/practiesCheckBox_008/user/listUsers?name=s&password=s'"/></td>
	   	</tr>
	   </table>
   </form>
  </body>
</html>
